package whsw.tool;

/**
 * 断言工具
 * 在解析字符串时, 当字符串不符合某种格式, 则抛出带有指定信息的异常
 *
 * @author flutterdash@qq.com
 * @since 2021/6/20 16:52
 */
public class AssertParser {

    public static int parserInt(String str, String msg) {
        try {
            return Integer.parseInt(str);
        } catch (Exception e) {
            throw new RuntimeException(msg);
        }
    }

    public static char parserSex(String str, String msg) {
        try {
            char sex = str.charAt(0);
            if (!Character.isLetter(sex))
                throw new Exception();
            return sex;
        } catch (Exception e) {
            throw new RuntimeException(msg);
        }
    }

}
